import Vue from 'vue'
import Vuex from 'vuex'
import util from '@/util/util';

Vue.use(Vuex)

const state = {
    memberMap:{},//会员卡详情
    orderInfo:{
        toshopdetail:{},//这些数据用于请求外部支付页面
        orderMap:{}//订单数据
    },
    FDLBLST:[]//会员查询对应的店铺列表
}

const mutations = {
    setMemberMap(state,param){
        state.memberMap = param;
    },
    setOrderInfo(state,param){
        state.orderInfo.toshopdetail = param.toshopdetail;
        state.orderInfo.orderMap = param.orderMap;
    },
    setOtherGoods(state,param){
        state.FDLBLST = param;
    }
}

const actions = {
    //卡信息数据
    loadCardDetail(store,params){
        util.axiosPost('/service/consume/MembershipServelt.do',params).then(resp=>{
            console.log(resp.data);
            store.commit('setMemberMap',resp.data);
        });
    },
    //点击购买 创建订单
     createOrder(store,params){
        util.axiosPost('/service/consume/MembershipCardOrder.do',params).then(resp=>{
            console.log(resp.data);
            store.commit('setOrderInfo',resp.data);
        });
    },
    queryOtherGoods(store,params){
        util.axiosPost('/service/consume/BussinessSearchServlet.do',params).then(resp=>{
            console.log(resp.data);
            store.commit('setOtherGoods',resp.data);
        });
    }
}

const getters = {
    getMemberMap(state){
        return state.memberMap;
    },
    getOrderInfo(state){
        return state.orderInfo;
    },
    getFDLBLST(state){
        console.log(state.FDLBLST);
        return state.FDLBLST;
    }

}

export default ({
  state,
  getters,
  actions,
  mutations
})
